package com.blog.applet.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.blog.applet.common.core.controller.BaseController;
import com.blog.applet.common.core.domain.AjaxResult;
import com.blog.applet.common.core.domain.PageResult;
import com.blog.applet.domain.BlogArticles;
import com.blog.applet.service.BlogArticlesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/***
 * @Author 鳄鱼杆
 * @Date 2025/5/14 20:16
 */
@RestController
@RequestMapping("/article")
public class BlogArticlesController extends BaseController {

    @Autowired
    private BlogArticlesService blogArticlesService;

    /**
     * 分页查询所有文章
     * @param pageNum 当前页码
     * @param pageSize 大小
     * @param categoryId 分类id
     * @return PageResult
     */
    @GetMapping("/listPage")
    public AjaxResult listAll(
            @RequestParam(defaultValue = "1") Integer pageNum,
            @RequestParam(defaultValue = "10") Integer pageSize,
            @RequestParam(required = false) Long categoryId) {

        // 执行分页查询
        IPage<BlogArticles> articlePage = blogArticlesService.selectPage(pageNum, pageSize,categoryId);

        return getPageData(articlePage);
    }

    /**
     * 根据id查询文章
     * @param id 文章id
     * @return BlogArticles
     */
    @GetMapping("/{id}")
    public BlogArticles getArticle(@PathVariable Long id) {

        return blogArticlesService.getById(id);
    }




}
